package com.ruoyi.web.controller.interview;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.interview.domain.entity.ReportResponseEntity;
import com.ruoyi.interview.service.IInterviewReportService;
import com.ruoyi.interview.service.IReportGenerateService;
import com.ruoyi.web.util.ChatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 面试报告接口
 * @author huangjie
 * @date 2025/11/27
 */
@RestController
@RequestMapping("/interview/report")
public class InterviewReportController {
    @Autowired
    private IInterviewReportService interviewReportService;

    @GetMapping("/genReport")
    public AjaxResult genReport(Long recordId){
        //生成提示词
       String prompt =interviewReportService.genPrompt(recordId);
        //根据提示次调用ai接口，获得评价
       String report =ChatUtil.getService(IReportGenerateService.class).generateReport(prompt);
       //转为对象格式
        ReportResponseEntity reportResponseEntity = JSONObject.parseObject(report, ReportResponseEntity.class);
        //入库
        reportResponseEntity.setRecordId(recordId);
        interviewReportService.saveReport(reportResponseEntity);

        //返回数据
        return AjaxResult.success(JSONObject.parseObject(report));
    }
}
